Docker : Use Dockerfile#2
2015/06/27 |
Use Dockerfile and create Docker images automatically.
It is also useful for configuration management. |
|
[1] | For example, Create a Dockerfile to install httpd and add index.html, and also start httpd with 80 port. |
[root@dlp ~]#
vi Dockerfile # create new FROM centos MAINTAINER serverworld <admin@srv.world> RUN yum -y install httpd RUN echo "Hello DockerFile" > /var/www/html/index.html EXPOSE 80 CMD ["-D", "FOREGROUND"] ENTRYPOINT ["/usr/sbin/httpd"] # build image ⇒ docker build -t [image name]:[tag] . [root@dlp ~]# docker build -t web_server:latest . Sending build context to Docker daemon 10.24 kB Step 0 : FROM centos ---> 7322fbe74aa5 Step 1 : MAINTAINER serverworld <admin@srv.world> ---> Running in fa5364b3d41f ---> 57d8fd36b7f7 ..... ..... Removing intermediate container 3efa8e1dcae9 Successfully built 7c39aaa338b4[root@dlp ~]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE web_server latest 7c39aaa338b4 24 seconds ago 283.9 MB docker.io/centos latest ce20c473cd8a 8 weeks ago 172.3 MB # run Container on background [root@dlp ~]# docker run -d -p 80:80 web_server [root@dlp ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES eda2b1482272 web_server "/usr/sbin/httpd -D F" 35 seconds ago Up 34 seconds 0.0.0.0:80->80/tcp mad_bhabha[root@node02 ~]# curl http://localhost/ Hello DockerFile |